<template>
  <div class="container">
    <div class="container-inner">
      <van-form ref="form" label-width="110px" scroll-to-error :show-error-message="false">
        <div class="card">
          <div class="card-bar">
            <div class="card-bar-title">基本信息</div>
          </div>
          <div class="card-container">
            <van-field v-model="formData.name" readonly label="姓名">
            </van-field>
            <van-field v-model="formData.tel" readonly label="联系方式">
            </van-field>
            <van-field v-model="formData.card_no" readonly label="身份证号">
            </van-field>
            <van-field v-model="formData.sex_name" label="性别" readonly>
            </van-field>
            <van-field
              readonly
              label="所属区域"
              v-model="
                formData.area_name +
                '/' +
                formData.street_name +
                '/' +
                formData.community_name
              "
            >
            </van-field>
            <van-field v-model="formData.address" readonly label="详细地址">
            </van-field>
            <van-field v-model="formData.quarter" readonly label="所属小区">
            </van-field>
            <van-field v-model="healthData.create_time" readonly label="填报时间">
            </van-field>
          </div>
          <div class="card-bar">
            <div class="card-bar-title">基本情况</div>
          </div>
          <div class="card-container">
            <van-field
              v-model="healthData.body_situation_name"
              readonly
              :error="healthData.body_situation == '1'"
              label="身体情况"
            >
            </van-field>
            <van-field
              v-if="healthData.body_situation == '1'"
              v-model="healthData.symptom"
              readonly
              error
              label="病症病状"
            >
            </van-field>
            <van-field
              v-model="healthData.temperature"
              :error="healthData.temperature > 37.2"
              readonly
              label="体温"
            >
            </van-field>
            <van-field
              v-model="
                healthData.area_name +
                '/' +
                healthData.street_name +
                '/' +
                healthData.community_name
              "
              readonly
              label="今日所属区域"
            >
            </van-field>
            <van-field v-model="healthData.quarter" readonly label="今日所属小区">
            </van-field>
            <van-field v-model="healthData.address" readonly label="今日详细地址">
            </van-field>
          </div>
          <div class="card-bar">
            <div class="card-bar-title">流行病学史</div>
          </div>
          <div class="card-container">
            <div class="card-container-item">
              <div class="card-item-label">{{ dict.epidemic.desc1 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_lxbxs_zgdqljs_br_name"
                  readonly
                  :error="healthData.is_lxbxs_zgdqljs_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_lxbxs_zgdqljs_gtjzz_name"
                  readonly
                  :error="healthData.is_lxbxs_zgdqljs_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
            <div class="card-container-item">
              <div class="card-item-label">{{ dict.epidemic.desc2 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_lxbxs_jwljs_br_name"
                  readonly
                  :error="healthData.is_lxbxs_jwljs_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_lxbxs_jwljs_gtjzz_name"
                  readonly
                  :error="healthData.is_lxbxs_jwljs_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
            <div class="card-container-item">
              <div class="card-item-label">{{ dict.epidemic.desc3 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_lxbxs_jcfrhz_br_name"
                  readonly
                  :error="healthData.is_lxbxs_jcfrhz_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_lxbxs_jcfrhz_gtjzz_name"
                  readonly
                  :error="healthData.is_lxbxs_jcfrhz_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
            <div class="card-container-item">
              <div class="card-item-label">{{ dict.epidemic.desc4 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_lxbxs_jcxggrz_br_name"
                  readonly
                  :error="healthData.is_lxbxs_jcxggrz_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_lxbxs_jcxggrz_gtjzz_name"
                  readonly
                  :error="healthData.is_lxbxs_jcxggrz_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
            <div class="card-container-item">
              <div class="card-item-label">{{ dict.epidemic.desc5 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_lxbxs_jjx_br_name"
                  readonly
                  :error="healthData.is_lxbxs_jjx_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_lxbxs_jjx_gtjzz_name"
                  readonly
                  :error="healthData.is_lxbxs_jjx_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
          </div>
          <div class="card-bar">
            <div class="card-bar-title">风险人群</div>
          </div>
          <div class="card-container">
            <div class="card-container-item">
              <div class="card-item-label">{{ dict.risk.desc1 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_fxrq_lxbxs_br_name"
                  readonly
                  :error="healthData.is_fxrq_lxbxs_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_fxrq_lxbxs_gtjzz_name"
                  readonly
                  :error="healthData.is_fxrq_lxbxs_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
            <div class="card-container-item">
              <div class="card-item-subtitle">{{ dict.risk.subtitle1 }}</div>
              <div class="card-item-label">{{ dict.risk.desc2 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_fxrq_jkll_br_name"
                  readonly
                  :error="healthData.is_fxrq_jkll_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_fxrq_jkll_gtjzz_name"
                  readonly
                  :error="healthData.is_fxrq_jkll_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
            <div class="card-container-item">
              <div class="card-item-label">{{ dict.risk.desc3 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_fxrq_jzyx_br_name"
                  readonly
                  :error="healthData.is_fxrq_jzyx_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_fxrq_jzyx_gtjzz_name"
                  readonly
                  :error="healthData.is_fxrq_jzyx_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
            <div class="card-container-item">
              <div class="card-item-label">{{ dict.risk.desc4 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_fxrq_xgfy_br_name"
                  readonly
                  :error="healthData.is_fxrq_xgfy_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_fxrq_xgfy_gtjzz_name"
                  readonly
                  :error="healthData.is_fxrq_xgfy_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
            <div class="card-container-item">
              <div class="card-item-label">{{ dict.risk.desc5 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_fxrq_bj_br_name"
                  readonly
                  :error="healthData.is_fxrq_bj_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_fxrq_bj_gtjzz_name"
                  readonly
                  :error="healthData.is_fxrq_bj_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
            <div class="card-container-item">
              <div class="card-item-label">{{ dict.risk.desc6 }}</div>
              <div class="card-item-content">
                <van-field
                  label="本人"
                  v-model="healthData.is_fxrq_nrsq_br_name"
                  readonly
                  :error="healthData.is_fxrq_nrsq_br == '1'"
                >
                </van-field>
                <van-field
                  label="共同居住者"
                  v-model="healthData.is_fxrq_nrsq_gtjzz_name"
                  readonly
                  :error="healthData.is_fxrq_nrsq_gtjzz == '1'"
                >
                </van-field>
              </div>
            </div>
          </div>
          <div class="card-bar">
            <div class="card-bar-title">返校信息</div>
          </div>
          <div class="card-container">
            <van-field v-model="formData.return_time" readonly label="返校时间">
            </van-field>
            <van-field
              v-model="formData.departure_place"
              readonly
              label="出发地"
            >
            </van-field>
            <van-field
              v-model="formData.departure_time"
              readonly
              label="出发时间"
            >
            </van-field>
          </div>
        </div>
      </van-form>
    </div>
    <div class="bottom-bar" v-if="this.route.type=='confirm'">
      <van-button
        class="bottom-bar-btn"
        block
        size="large"
        color="#D58913"
        type="info"
        text="确认返校"
        @click="SubmitAction"
      />
    </div>
  </div>
</template>

<script>
import dict from './dict/others'
import {
  getReturnInfo,
  getReturnHealthInfo,
  updateConfirmReturn,
} from '@/api/school'

export default {
  data() {
    return {
      dict,
      route: {},
      formData: {},
      healthData: {},
    }
  },
  computed: {},
  watch: {},
  mounted() {
    this.route = this.$route.query
    console.log(this.route)
    this.init()
  },
  methods: {
    async init() {
      const returnData = await getReturnInfo(this.route)
      if (returnData.data.errcode == '0') {
        this.formData = returnData.data.data
      }
      const returnHealthData = await getReturnHealthInfo(this.route)
      if (returnHealthData.data.errcode == '0') {
        this.healthData = returnHealthData.data.data
      }
    },
    async SubmitAction() {
      this.$dialog
        .confirm({
          title: '是否确认返校',
          message: '',
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          confirmButtonColor: '#D58913',
          beforeClose: async (action, done) => {
            if (action === 'confirm') {
              const confirmData = await updateConfirmReturn(this.route)
              if (confirmData.data.errcode == 0) {
                this.$toast('操作成功')
                setTimeout(() => {
                 this.$router.push({
                    path: '/school',
                    query:{
                      ...this.$store.state.user.userInfo
                    }
                  })
                }, 500)
                done()
              } else {
                this.$toast(confirmData.data.errmsg)
                done()
              }
            } else {
              done()
            }
          },
        })
        .catch(() => {})
    },
  },
}
</script>

<style lang="less" scoped>
.container /deep/ .van-checkbox {
  min-height: 30px;
}

.container /deep/ .van-field__label span {
  display: inline-block;
  padding-left: 5px;
  width: 90%;
  text-align-last: justify;
}

.container {
  background: #f2f7fb;
  width: 100%;
  height: 100vh;
  box-sizing: border-box;

  &-inner {
    padding: 10px 20px 50px;
    .card {
      background: inherit;

      &-container {
        border-radius: 10px;
        overflow: hidden;
        background-color: white;
        padding: 10px;

        &-item {
          margin-bottom: 10px;
        }

        &-item:not(:last-child) {
          border-bottom: 1px solid #ebedf0;
        }
      }

      &-item {
        &-subtitle {
          padding: 0px 5px;
          font-size: 15px;
          margin-bottom: 5px;
        }

        &-label {
          color: #a0a0a0;
          font-size: 14px;
          position: relative;
          padding-left: 20px;
          padding-right: 10px;
        }
      }
    }
  }
  .bottom-bar {
    position: absolute;
    bottom: 0;
    width: 100%;
  }
}
</style>
